package com.jie.deletefile.xListview.xlistview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.jie.deletefile.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class XListActivity extends AppCompatActivity implements XListView.IXListViewListener {

    private List<String> datas;
    private MyAdapter adapter;
    private XListView xListView;
    private String TAG = "TAG";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xlist);
        datas = getDatas();
        Log.e(TAG, "onCreate: "+datas.size());
        adapter = new MyAdapter(this, R.layout.xlist_item,datas);
        xListView = (XListView) findViewById(R.id.xlist);
        xListView.setAdapter(adapter);
        xListView.setPullLoadEnable(true);
        xListView.setPullRefreshEnable(true);
        xListView.setXListViewListener(this);
        xListView.setRefreshTime(getTime());
    }

    private List<String> getDatas() {
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            data.add("条目" + i+"");
        }
        return data;
    }

    @Override
    public void onRefresh() {
        datas.addAll(getDatas());
        adapter.notifyDataSetChanged();
        xListView.stopRefresh();
        xListView.stopLoadMore();
    }

    @Override
    public void onLoadMore() {

    }

    private String getTime(){


        SimpleDateFormat format=new SimpleDateFormat("hh:mm:ss");

        Date date=new Date();
        String time = format.format(date);
        return time;


    }
}

